package com.chenl.provider.DEMOS.设计模式.策略模式.one;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.math.BigDecimal;

@Getter
@AllArgsConstructor
public enum AnimalEnum {
    ONE(1, "person"),
    TWO(2, "dog"),
    THREE(3, "cat");

    private final int code;
    private final String msg;

    public Integer code() {
        return this.code;
    }

    public String msg() {
        return this.msg;
    }

    public static String getDesc(Integer code) {
        AnimalEnum[] animalEnums = values();
        for (AnimalEnum animalEnum : animalEnums) {
            if (BigDecimal.valueOf(animalEnum.code()).compareTo(BigDecimal.valueOf(code)) == 0) {
                return animalEnum.msg();
            }
        }
        return null;
    }

    public static Integer getCode(String desc) {
        AnimalEnum[] animalEnums = values();
        for (AnimalEnum animalEnum : animalEnums) {
            if (animalEnum.msg.equals(desc)) {
                return animalEnum.code();
            }
        }
        return null;
    }

}
